#include <iostream>
//单例的使用，和零成本多态
template<typename T>
class Animal
{

public:
     void speak()
     {
        ((T*)this)->speak();
     }
};

class dog : public Animal<dog>
{
public:
    void speak()
    {
        std::cout << "汪汪汪\n";
    }
};

class cat : public Animal<cat>
{
public:
    void speak()
    {
        std::cout << "喵喵喵\n";
    }
};
template <typename T>
void Speak(Animal<T> &a)
{
    a.speak();
}
int main()

{
    dog d;
    Speak(d);
    cat c;
    Speak(c);

    return 0;
}